package com.example.pceb.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.pceb.DTO.ResumeDto;
import com.example.pceb.entity.Recruit;
import com.example.pceb.mapper.RecruitMapper;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecruitService extends ServiceImpl<RecruitMapper,Recruit> {
    @Autowired
    private RecruitMapper recruitMapper;

    public List<Recruit> recommendJobs(ResumeDto resume) {
        QueryWrapper<Recruit> wrapper = new QueryWrapper<>();
        wrapper.eq("isPass", 1);

        // 只要有一个字段模糊匹配即可
        wrapper.and(w -> {
            boolean hasCondition = false;
            if (resume.getExpectJob() != null && !resume.getExpectJob().isEmpty()) {
                w.or().like("identity", resume.getExpectJob());
                hasCondition = true;
            }
            if (resume.getExpectIndustry() != null && !resume.getExpectIndustry().isEmpty()) {
                w.or().like("details", resume.getExpectIndustry());
                hasCondition = true;
            }
            if (resume.getAdvantage() != null && !resume.getAdvantage().isEmpty()) {
                w.or().like("details", resume.getAdvantage());
                hasCondition = true;
            }
            if (resume.getUsed() != null && !resume.getUsed().isEmpty()) {
                w.or().like("details", resume.getUsed());
                hasCondition = true;
            }
            if (resume.getEducation() != null && !resume.getEducation().isEmpty()) {
                w.or().like("education", resume.getEducation());
                hasCondition = true;
            }
            // 如果没有任何条件，默认true，避免SQL错误
            if (!hasCondition) {
                w.or().isNotNull("id");
            }
        });

        wrapper.last("limit 10");
        return recruitMapper.selectList(wrapper);
    }

}
